package com.school.util;

import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RepUtil {

	/**
	 * 添加Cache标识
	 * @param rep
	 */
	public static void repCache(HttpServletResponse rep){
		rep.addHeader("Cache-Control","no-cache,no-store,must-revalidate");
		rep.addHeader("Pragma", "no-cache");
		rep.addHeader("Expires", "0");
	}
	/**
	 * 跨域链接头
	 * @param rep
	 */
	public static void repPake(HttpServletResponse rep){
		rep.addHeader("Access-Control-Allow-Origin", "*");
		rep.addHeader("Access-Control-Allow-Header", "Origin,X-Requested-With,Content-Type,Accept");
	}
	/**
	 * 
	 * 查找文件访问前缀
	 * @param oClass
	 * @return
	 */
	public static String findAddress(HttpServletRequest req){
		//File f = new File(this.getClass().getResource("/").getPath());
		  // URL xmlpath = oClass.getClass().getClassLoader().getResource("");
		   //String strPath=xmlpath.toString().split("WEB-INF")[0]+"images/schools/"+oBasicsInfo.getLogo();
		String strPath="";   
		   try {
			   String strName=	req.getServletContext().getContextPath();
			   int nPort=req.getServerPort();
			   strPath ="http://"+InetAddress.getLocalHost().getHostAddress()+":"+nPort+strName+"/myImages/schools/";
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return strPath;
	}
}
